package Yki.PaperPlaneClient;

import Yki.PaperPlaneClient.Friends.Friend;
import Yki.PaperPlaneClient.Friends.FriendCreater;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class FriendContent extends Activity {
	Context context;
	
	TextView[] textViewAttribute;
	int friendId;
	Friend friend;
	
	AbsoluteLayout layout;
	ImageView imageViewPortrait;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		setContentView(R.layout.friend_content); 
		String idStr = getIntent().getStringExtra("ID");
		friendId = Integer.valueOf(idStr);
        friend = FriendCreater.getFriendByIndex(friendId);
		
		context = this;
		
		layout = (AbsoluteLayout)findViewById(R.id.AbsoluteLayoutFriendContent);
        imageViewPortrait = (ImageView)findViewById(R.id.ImageViewFriendPortrait);
        imageViewPortrait.setImageResource(friend.getPortraitResource());
        
        Typeface typeface = 
        	Typeface.createFromAsset(context.getAssets(), "minishanhu.ttf");
        
		textViewAttribute = new TextView[4];
		int id[] = {R.id.TextViewFriendContentName, R.id.TextViewFriendContentGender,
				R.id.TextViewFriendContentLocation, R.id.TextViewFriendContentSignature };
		String text[] = { friend.getName(), "Gender", "Location", "Signature" };
		int[] tagWidth = new int[4];
        for( int i = 0; i < textViewAttribute.length; i++ ) {
        	tagWidth[i] = text[i].length()*23;
        	textViewAttribute[i] = (TextView)findViewById(id[i]);
        	textViewAttribute[i].setTypeface(typeface);
        	textViewAttribute[i].setTextSize(20);
        	textViewAttribute[i].setText(text[i]);
        	textViewAttribute[i].setTextColor(Color.BLACK);
        	textViewAttribute[i].setWidth(tagWidth[i]);
        	textViewAttribute[i].setHeight(35);
        }
        textViewAttribute[3].setHeight(70);

    	TextView textViewGender = new TextView(context);
    	TextView textViewLocation = new TextView(context);
    	TextView textViewSignature = new TextView(context);
    	
    	String[] contents = new String[3];
    	contents[0] = friend.getGender().toString();
    	contents[1] = friend.getLocation();
    	contents[2] = friend.getSignature();
    	textViewGender.setText(contents[0]);
    	textViewLocation.setText(contents[1]); 
    	textViewSignature.setText("    "+contents[2]);
		
//    	textViewGender.setTypeface(typeface);
//    	textViewLocation.setTypeface(typeface);
//    	textViewSignature.setTypeface(typeface);
    	int textSize = 19;
    	textViewGender.setTextSize(textSize);
    	textViewLocation.setTextSize(textSize);
    	textViewSignature.setTextSize(textSize);
    	
    	textViewGender.setTextColor(Color.BLACK);
    	textViewLocation.setTextColor(Color.BLACK);
    	textViewSignature.setTextColor(Color.BLACK);
    	
    	int[] contentWidth = new int[2];
    	for(int i = 0; i < 2; i++) {
    		contentWidth[i] = (contents[i].length()) * 23;
    	}
		AbsoluteLayout.LayoutParams genderLayoutParams = 
			new AbsoluteLayout.LayoutParams( contentWidth[0], 28+4, 99+tagWidth[1], 395-2);
		AbsoluteLayout.LayoutParams locationLayoutParams = 
			new AbsoluteLayout.LayoutParams( contentWidth[1], 28+8, 99+tagWidth[1], 460-4);
		AbsoluteLayout.LayoutParams signatureLayoutParams = 
			new AbsoluteLayout.LayoutParams( 277, 172, 99, 581);

		layout.addView(textViewGender, genderLayoutParams);
		layout.addView(textViewLocation, locationLayoutParams);
		layout.addView(textViewSignature, signatureLayoutParams);
	}

}
